// myquanhq.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    url: {
      exchangeCode: app.url.baseUrl + "/my/exchangeCode"
    },
    dd: '',
    code: ''
  },

  onLoad: function (options) {

  },
  input: function (e) {
    var v = e.detail.value
    this.setData({ code: v })
  },
  //兑换优惠劵
  exchangeCode: function () {
    var that = this
    this.data.code = this.data.code.replace(/\s/g, "");
    this.data.code = this.data.code.toLocaleUpperCase();
    console.log(this.data.code);
    if (this.data.code.length != 12) {
      wx.showModal({
        content: '优惠劵输入有误',
        showCancel:false
      })
      return
    }
    this.setData({ dd: "1" })
    app.ajax(this.data.url.exchangeCode, { id: this.data.code }, function (res) {
      if (res.data.code == 2000) {
        wx.showModal({
          content: res.data.msg,
          showCancel: false,
          success: function(res) {
            wx.navigateBack({})
          },
          fail: function(res) {},
          complete: function(res) {},
        })
      } else {
        wx.showModal({
          content: res.data.msg,
          showCancel: false,
          complete: function (res) { 
            that.setData({dd:''})
          },
        })
      }
    })
  }
})